package org.noote.test_radar;


import javax.microedition.khronos.opengles.GL10;

import org.noote.libs.sogle.Renderer;
import org.noote.libs.sogle.Vector3D;
import org.noote.libs.radar.Mesh_Radar;

import android.app.Activity;
import android.content.Context;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.view.MotionEvent;

public class TestRadar_Activity extends Activity {
	
    RenderOGL mRenderer;
    
    public class RenderOGL extends Renderer {

	       public RenderOGL(Context context)
	        {
	        	super(context);
	        }
		
	        @Override
	        public void onCreateScene(GL10 gl)
	    	{
	    		super.onCreateScene(gl);
	    		
	    		setBackGroundColor(0.5f, 0.5f, 1.0f);
	    		_camera.setLookAt(new Vector3D(0, 0, -10), new Vector3D(0, 0, 1), 0);
	    		lighting(false);
	    		
	            float depth[] =
	                {
	                	 0,  0,  1,  1,  1,  1,  1,  1,  1,  0,
	                	 0,  0,  5,  5,  5,  5,  5,  5,  1,  0,
	                	 0,  0,  6,  6,  6,  5,  5,  5,  1,  0,
	                	 0,  0,  6,  6,  6,  5,  5,  5,  1,  0,
	                	 0,  0,  6,  6,  5,  5,  5,  5,  1,  0,
	                	 0,  0,  5,  5,  5,  5,  5,  5,  1,  0,
	                	 0,  0,  5,  5,  5,  5,  5,  5,  1,  0,
	                	 0,  0,  1,  1,  1,  1,  1,  1,  1,  0
	                };
	                Mesh_Radar radar=new Mesh_Radar();
	                radar.create(160, 75, 0.5f, 0.5f, 1.0f);
	                radar.setMap(10, 8, depth);
	                radar.build();
	                
	                radar.setColor(1, 1, 1, 1);
	                radar.setPosition(0, 0, 0);
	                _listObjects.add(radar);
	    	}
	}
    
	class ClearGLSurfaceView extends GLSurfaceView {
	    public ClearGLSurfaceView(Context context) {
	        super(context);
	        mRenderer = new RenderOGL(context);
	        setRenderer(mRenderer);
	    }

	    @Override
		public boolean onTouchEvent(final MotionEvent event) {
	        queueEvent(new Runnable(){
	            @Override
				public void run() {

	            	float x = event.getX()/getWidth();
	            	float y = event.getY()/getHeight();
	            	
	            	if(y>0.66 && x>0.33 && x<0.66)
	            		mRenderer._camera.move_forward(-0.125f);
	            	else if(y<0.33 && x>0.33 && x<0.66)
	            		mRenderer._camera.move_forward(0.125f);
	            	else if(x>0.66 && y>0.33 && y<0.66)
	            		mRenderer._camera.move_left(0.125f);
	            	else if(x<0.33 && y>0.33 && y<0.66)
	            		mRenderer._camera.move_left(-0.125f);            		
	            	else if(x>0.66 && y>0.66)
	            		mRenderer._camera.rotate_view_left(0.0125f);
	            	else if(x<0.33 && y>0.66)
	            		mRenderer._camera.rotate_view_left(-0.0125f);            		
	            }
            });
            return true;
        }
	}

	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mGLView = new ClearGLSurfaceView(this);
        setContentView(mGLView);
	}
    
    @Override
    protected void onPause() {
        super.onPause();
        mGLView.onPause();
    }

    @Override
    protected void onResume() {
        super.onResume();
        mGLView.onResume();
    }

    private GLSurfaceView mGLView;
}